<div class="level">
  <div class="level-left">
    <div class="level-item">
      <h2 class="subtitle">Issues</h2>
    </div>
  </div>
  <%= if verified?(@conn) do %>
    <div class="level-right">
      <div class="level-item">
        <%= if verified?(@current_user) do %>
          <a class="button is-success" href="<%= Routes.issue_path(@conn, :new, @repo.owner_login, @repo) %>">New</a>
        <% else %>
          <p class="button tooltip is-success" data-tooltip="Verify your account" disabled>New</p>
        <% end %>
      </div>
    </div>
  <% end %>
</div>

<%= with page <- paginate(@conn, @issues) do %>
  <table class="table issues-table is-fullwidth">
    <thead>
      <tr>
        <td class="selection">
          <label class="checkbox">
            <input type="checkbox">
          </label>
        </td>
        <td colspan="3">
          <nav class="columns">
            <div class="column">
              <div class="field is-grouped">
                <div class="control">
                  <%= if :open in @q.status do %>
                    <%= status_button(@conn, :open, class: "has-text-grey-light has-badge-rounded has-badge-success", data_badge: @repo_open_issue_count) %>
                  <% else %>
                    <%= status_button(@conn, :open, class: "has-badge-rounded has-badge-success has-badge-outlined", icon: [class: "has-text-success"], data_badge: @repo_open_issue_count) %>
                  <% end %>
                </div>
                <div class="control">
                  <%= if :close in @q.status do %>
                    <%= status_button(@conn, :close, class: "has-text-grey-light has-badge-rounded has-badge-danger", data_badge: @repo_close_issue_count) %>
                  <% else %>
                    <%= status_button(@conn, :close, class: "has-badge-rounded has-badge-danger has-badge-outlined", icon: [class: "has-text-danger"], data_badge: @repo_close_issue_count) %>
                  <% end %>
                </div>
              </div>
            </div>
            <div class="column is-three-fifths">
              <%= form_for @conn, Routes.issue_path(@conn, :index, @repo.owner_login, @repo), [method: "get"], fn f -> %>
                <div class="field has-addons">
                  <div class="control is-expanded">
                    <%= text_input f, :q, class: "input", value: encode_search_query(@q), placerholder: "Search all issues" %>
                  </div>
                  <p class="control">
                    <%= submit("Search", class: "button") %>
                  </p>
                </div>
              <% end %>
            </div>
            <div class="column">
              <div class="field has-addons">
                <div class="control">
                  <div class="issue-label-dropdown dropdown is-hoverable">
                    <div class="dropdown-trigger">
                      <button class="button" aria-haspopup="true">
                        <span>Labels</span>
                        <span class="icon is-small">
                          <i class="fa fa-angle-down" aria-hidden="true"></i>
                        </span>
                      </button>
                    </div>
                    <div class="dropdown-menu">
                      <div class="dropdown-content">
                        <%= for label <- @repo.issue_labels do %>
                          <div class="dropdown-item">
                            <%= if label.name in @q.labels do %>
                              <%= label_button(@conn, label, class: "edit is-active", href: current_path(@conn, q: encode_search_query(@q, labels: List.delete(@q.labels, label.name)))) %>
                            <% else %>
                              <%= label_button(@conn, label, class: "edit", href: current_path(@conn, q: encode_search_query(@q, labels: [label.name|@q.labels]))) %>
                            <% end %>
                          </div>
                        <% end %>
                      </div>
                    </div>
                  </div>
                </div>
                <%= if authorized?(@conn, @repo, :admin) do %>
                  <div class="control">
                    <a href="<%= Routes.issue_label_path(@conn, :index, @repo.owner_login, @repo) %>" class="button">
                      <span class="icon"><i class="fa fa-cog"></i></span>
                    </a>
                  </div>
                <% end %>
              </div>
            </div>
          </nav>
        </td>
      </tr>
    </thead>
    <tbody>
      <%= unless Enum.empty?(page.slice) do %>
        <%= for {issue, comment_count} <- page.slice do %>
          <tr>
            <td class="selection">
              <label class="checkbox">
                <input type="checkbox">
              </label>
            </td>
            <td class="status">
              <%= status_icon(issue, class: "has-text-success") %>
            </td>
            <td>
              <div class="issue-title has-text-weight-bold">
                <a href="<%= Routes.issue_path(@conn, :show, @repo.owner_login, @repo, issue.number) %>"><%= issue.title %></a>
                <div class="issue-labels">
                  <%= for label <- issue.labels, do: label_button(@conn, label) %>
                </div>
              </div>
              <div class="issue-info">
                #<%= issue.number %> opened <%= datetime_format(issue.inserted_at, "{relative}") %> by <a href="<%= Routes.user_path(@conn, :show, issue.author) %>" class="has-text-black"><%= issue.author.login %></a>
              </div>
            </td>
            <td class="has-text-right">
              <%= if comment_count > 0 do %>
              <a href="<%= Routes.issue_path(@conn, :show, @repo.owner_login, @repo, issue.number) %>" class="button is-small is-white">
                <span class="icon"><i class="fa fa-comment-alt"></i></span>
                <span><%= comment_count - 0 %></span>
              </a>
              <% end %>
            </td>
          </tr>
        <% end %>
      <% else %>
        <tr>
          <td colspan="3">
            <article class="message is-light">
              <div class="message-body">No issues found.</div>
            </article>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
  <%= pagination(@conn, page) %>
<% end %>
